package com.sky.demo.java;

import java.util.Arrays;

public class Comparable_demo {

    public static void main(String[] args) {
        Employee[] staff = new Employee[2];

        staff[0] = new Employee("a", 1000);
        staff[1] = new Employee("b", 2000);

        Arrays.sort(staff);
        for(Employee e : staff){
            System.out.println("name= " + e.getName() + ",salary= " + e.getSalary());
        }
    }

    public static class Employee implements Comparable<Employee> {

        private String name;
        private double salary;

        public Employee(String name, double salary) {
            this.name = name;
            this.salary = salary;
        }


        public String getName() {
            return name;
        }

        public double getSalary() {
            return salary;
        }


        public void raiseSalary(double byPercent){
            double raise = salary * byPercent / 100;
            salary += raise;
        }

        @Override
        public int compareTo(Employee o) {
            return Double.compare(salary, o.salary);
        }
    }
}
